﻿<?php
//    require_once '../wxpay/example/WxPay.JsApiPay.php';
    require_once 'WxPay.JsApiPay.php';
//    require_once '../wxpay/lib/WxPay.Api.php';
//    require_once '../../../simplewind/extend/alipay/alipay.php';

//    $pay  = new JsApiPay();
//    $openid =  $pay->GetOpenid();
////var_dump($openid);exit;
//    function outJsPay($order,$openid)
//    {
//        $tools = new JsApiPay();
//        $input = new WxPayUnifiedOrder();
//        $input->SetBody("牛课宝典激活码");
////        $input->SetAttach($order['attach']);
//        $input->SetOut_trade_no($order['pay_code']);
////		$input->SetTotal_fee(intval(0.01 * 100));
//        $input->SetTotal_fee(intval(($order['totalfee']*100 - $order['youhui'])* 100));
//        $input->SetTime_start(date("YmdHis"));
//        $input->SetTime_expire(date("YmdHis", time() + 600));
//        $input->SetGoods_tag("test");
//        $input->SetNotify_url($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST']."/portal/pay/wxnotify");
//        $input->SetTrade_type("JSAPI");
//        $input->SetOpenid($openid);
//        $order = WxPayApi::unifiedOrder($input);
//        $jsApiParameters = $tools->GetJsApiParameters($order);
//        return $jsApiParameters;
//    }
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable = no"/>
		<meta name="format-detection" content="telephone=no">
        <title>在线支付</title>
        <link rel="stylesheet" href="/m/bfb/ui.min.css">
		<link rel="stylesheet" href="/m/bfb/style.css">
		<link rel="stylesheet" href="/m/swiper/css/swiper.min.css">
		<script src="/m/swiper/js/swiper.min.js"></script>
		<script src="/m/js/require.js"></script> 
		<script src="/m/bfb/zepto.min.js"></script> 
		<script>document.write("<script src='/m/js/app.js?_dc="+Math.random()+"'><\/script>");</script>
    </head>
<body>
<div class="page-group">

	<div class="page page-current" id="page-pay-v13">
		<header class="bar bar-nav">
		<!-- <a class="icon icon-left pull-left" id="paybackhome" href="/m/" style="display:none"></a>
		<a class="icon icon-left pull-left" id="payback" href="/m/" style="display:none"></a> -->
		<!-- <a class="iconfont iconfont-question pull-right" href="/m/faq/index.html"></a>  -->
		<div class="icon icon-left pull-left" id="backlink" ></div>
		<!-- <a class="iconfont iconfont-home pull-right" href="/m/"></a> -->
		<div class="pull-right" id="headimg"> </div>
		<h1 class="title" id="pay-title">在线支付</h1>
		 <div class="tab-index" id="paytabindex"></div></header>

		 <div class="content " id="pay-content" style="margin-top:2.1rem">
		  <div class="ui-container ">         
			  <input type="hidden" id="accountid" value="">
			  <input type="hidden" id="openid" value="">
			  <input type="hidden" id="description" value="">
			  <input type="hidden" id="userMessage" value="">
			  <input type="hidden" id="subject" value="">
			  <input type="hidden" id="totalfee" value="">
			  <input type="hidden" id="toAddress" value="">
			  <input type="hidden" id="toPerson" value="">
			  <input type="hidden" id="defee" value="">
			  <input type="hidden" id="totalamount" value="">
			  <input type="hidden" id="out_trade_no" value="">
              <input type="hidden" id="catid" value="">
			  <div id="payli"> </div>
		   </div>
		 </div>
 
		 <div class="payfoot">
		 <div class="pay-wrapper" style="text-align:center;line-height:50px;height:50px;background-color: #f8f8f8;">
		   <div class="row no-gutter">
			  <div class="col-50"> <div class="pay-heji" style="border-top: 1px solid rgba(0, 0, 0, 0.1);">合计：<span id="hejidiv"> </span></div> </div>
			  <div class="col-50"> <a class="external pay-queren" href="javascript:;" style="display:block;background-color: #f85;color: #fff;line-height: 50px; text-align:center;">确认购买</a> </div>
			</div>
		  </div>
		 </div>
	</div><!--main page end-->

　　<div class="popup page popup-order">
	<header class="bar bar-nav"><a class="button button-link button-nav pull-left close-popup"><span class="icon icon-left"></span></a><a class="button button-link button-nav pull-right close-popup">取消</a><h1 class="title noleft">确认您的订单</h1></header>
    <div class="content">
		<!-- <div class="content-block-title">确认您的订单</div> -->
			<div class="list-block">
			<ul id="orderli">
			  
			</ul>
		  </div><!--ul end-->
		  <div class="ui-form" id="payform" style="margin-top:10px">
			<div class="ui-form-item ui-form-item-l ui-border-tb" style=" ">
			<label class="ui-border-r">合　计：</label>
			 <span id="totalfeediv"> 元</span>
			</div>
			<div class="ui-form-item ui-form-item-l ui-border-b">
				<label class="ui-border-r">
				   手机号：
				</label>
				<input id="mob" type="tel" placeholder="请输入手机号码">
				<span id="mobclear" class="ui-icon-close"></span>
                        
            </div>

         </div>
     

          
		  <div class="list-block" id="paytype" style="margin-top:10px;display:none">
		  <!-- <div class="content-block-title">选择支付方式</div>
 -->
			<ul>
			  <li class="item-content checked" data-paytype="weixin">
				<div class="item-media"><i class="iconfont iconfont-iconfuzhi" style="color:#00CC00"></i></div>
				<div class="item-inner">
				  <div class="item-title">微信支付 <!-- <span class="badge">抢红包</span> --></div>
				  <div class="item-after"><i class="iconfont" style=""></i></i></div>
				</div>
			  </li>
			  <li class="item-content" data-paytype="alipay">
				<div class="item-media"><i class="iconfont iconfont-alipay" style="color:#0099FF"></i></div>
				<div class="item-inner">
				  <div class="item-title">支付宝支付</div>
				  <div class="item-after"> <i class="iconfont iconfont-round" style=""></i> </div>
				</div>
			  </li>
			</ul>
		  </div>


		   <div class="ui-btn-wrap" id="alipaybutdiv" style="display:none"> 
<!--			      <button id="alipaybut" class="ui-btn-lg ui-btn-primary">-->
			      <button id="newalipay" class="ui-btn-lg ui-btn-primary">
                    <i class="iconfont iconfont-alipay" ></i>
					<span style="padding-left:10px;">确认支付宝支付</span>
                  </button>
                 
				<div style="text-align:center;color:red;font-size:11px;padding-top:5px">好消息：满50即送现金红包！</div>
            </div>

			<div class="ui-btn-wrap" id="wxpaybutdiv"  style="display:none"> 
<!--			    <button class="ui-btn-lg ui-btn-primary" id="wxpaybut" >-->
			    <button class="ui-btn-lg ui-btn-primary" id="newwxpay" >
					确认微信支付
                </button> 

				<div style="text-align:center;color:red;font-size:11px;padding-top:5px">好消息：满50即送现金红包！</div>
  
            </div>

			<div class="ui-btn-wrap" id="paybutdiv"  style="display:none"> 
<!--			    <button class="ui-btn-lg ui-btn-primary" id="paybut" >-->
                <button class="ui-btn-lg ui-btn-primary" id="newpay" >
					立即支付
                </button>
				<div style="text-align:center;color:red;font-size:11px;padding-top:5px">好消息：满50即送现金红包！</div>
             </div>

			 <div style="font-size:13px;" id="resstate"> </div>
 

       </div><!--content end-->
	</div><!--popup page end-->
    <div id="form">
        <form id="myform" action="http://kaoguo8.tool8.cc/portal/pay/mobileorder" method="post" >

        </form>
    </div>

</div>
 
<script src="/m/bfb/ui.min.js"></script>
<script src="/m/js/pageinit.js"></script>
<script>
	$('#mob').focus(function(){
$('#mob').val('')
//          check()
        })
//	function check(){
//          var mobile=/^1[3456789]\d{9}$/;
//          if(mobile.test($('#mob').val())==false){
//
//              $('#mob').attr("placeholder","手机号码有误，请重填")
//              $('#mob').css({"border-color":"red","color":"red"});
//
//              return false;
//               
//          }else{
//          	$('#mob').attr("placeholder","")
//          	$('#mob').css({"border-color":"#efefef","color":"#333"});
//          }
//      }
        $('#mob').blur(function(){
        	 var mobile=/^1[3456789]\d{9}$/;
        	if(mobile.test($('#mob').val())==false){

                $('#mob').val("手机号码有误，请重填")
                $('#mob').css({"border-color":"red","color":"red"});

                return false;
                 
            }else{
//          	$('#mob').attr("placeholder","")
            	$('#mob').css({"border-color":"#efefef","color":"#333"});
            }
//$('#mob').val("手机号码有误，请重填")
//          check()
        })
        
    //paraName 等找参数的名称
    // function GetUrlParam(paraName) {
    //     var url = document.location.toString();
    //     var arrObj = url.split("?");
    //
    //     if (arrObj.length > 1) {
    //         var arrPara = arrObj[1].split("&");
    //         var arr;
    //
    //         for (var i = 0; i < arrPara.length; i++) {
    //             arr = arrPara[i].split("=");
    //
    //             if (arr != null && arr[0] == paraName) {
    //                 return arr[1];
    //             }
    //         }
    //         return "";
    //     }
    //     else {
    //         return "";
    //     }
    // }
    //
    // var urlname = GetUrlParam('name')
    // var urlprice = GetUrlParam('price')
    // var arr = getProductTypeInfo(urlname,urlprice)
    // console.log(arr)
    $(function () {
        $('#newpay').click(function () {
                var way= $('#paytype').find('.checked').attr('data-paytype')
            if(way == 'weixin'){
                if(isWeiXin()){
			
		
                    pay('微信支付')
                }else{
                    alert('该网页不支持外部支付，请在微信浏览器中打开')
                }
            }
            if(way== 'alipay'){
               var mobile=/^1[3456789]\d{9}$/;
        	console.log($('#mob').val())
        	console.log(mobile.test($('#mob').val()))
            if(mobile.test($('#mob').val())==false){

                 $('#mob').val("手机号码有误，请重填")
                $('#mob').css({"border-color":"red","color":"red"});

                return false;
            }else{
            	
            	pay('mobilealipay')
            }	
            }
        })
        $('#newalipay').click(function () {
        	var mobile=/^1[3456789]\d{9}$/;
        	console.log($('#mob').val())
        	console.log(mobile.test($('#mob').val()))
            if(mobile.test($('#mob').val())==false){

                 $('#mob').val("手机号码有误，请重填")
                $('#mob').css({"border-color":"red","color":"red"});

                return false;
            }else{
            	
            	pay('mobilealipay')
            }	
            
        })
        $('#newwxpay').click(function () {
        	var mobile=/^1[3456789]\d{9}$/;
        	console.log($('#mob').val())
        	console.log(mobile.test($('#mob').val()))
            if(mobile.test($('#mob').val())==false){

                 $('#mob').val("手机号码有误，请重填")
                $('#mob').css({"border-color":"red","color":"red"});

                return false;
            }else{
            	
            	pay('微信支付')
            }
            
        })
       
       function pay(way) {
           var mobile = $('#mob').val();
           var totalfee = $('#totalfee').val();
           var name = $('#description').val();
           var catid = $('#catid').val();
           var showid = (new Date().valueOf());
           var kefu = getQueryVariable('kefu')
           if(kefu){
               kefu = kefu
           }else{
               kefu = ''
           }
           var info = '';
           info += '{"items":"' + catid + '",';
           info += '"pay_info":"' + name + '",';
           info += '"mobile":"' + mobile + '",';
           info += '"qq":"' + '' + '",';
           info += '"totalfee":"' + totalfee + '",';
           info += '"pccode":"",'; ///  提交给 支付宝的标题写这里
           info += '"showid":"' + showid + '",';
           info += '"enname":"' + '' + '",';
           info += '"kefu":"' + kefu + '",';
           info += '"paybank":"' + way+ '"}';
           // console.log(info)

           // window.location = "http://"+window.location.host+'/m/pay/t.php';
           // var info = {items:22,pay_info:name,mobile:mobile,totalfee:totalfee,qq:'',paybank:'微信支付',showid:showid,pccode:'',enname:''};
           var html = `<input type="hidden" name="items" value='${catid}'>
<input type="hidden" name="pay_info" value='${name}'>
<input type="hidden" name="mobile" value='${mobile}'>
<input type="hidden" name="showid" value='${showid}'>
<input type="hidden" name="totalfee" value='${totalfee}'>
<input type="hidden" name="paybank" value='${way}'>
<input type="hidden" name="qq" value=''>
<input type="hidden" name="pccode" value=''>
<input type="hidden" name="enname" value=''>
<input type="hidden" name="kefu" value='${kefu}'>
                    `;
           $("#myform").html(html);
           $("#myform").submit();
       }
        //判断是否是微信浏览器的函数
        function isWeiXin(){
            //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
            var ua = window.navigator.userAgent.toLowerCase();
            //通过正则表达式匹配ua中是否含有MicroMessenger字符串
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                return true;
            }else{
                return false;
            }
        }
        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }

        


    })
</script>
</body>
</html>